package com.atbeijing.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark15_Oper_Transform {

    def main(args: Array[String]): Unit = {

        val conf = new SparkConf().setMaster("local[*]").setAppName("TransformOperator")
        val sc = new SparkContext(conf)

        // TODO 算子 - 转换 - KV - reduceByKey (2 / 10)
        val rdd : RDD[(String, Int)] = sc.makeRDD(
            List(
                ("a",1), ("b", 2), ("a", 3)
            )
        )
        // reduceByKey算子将相同key的数据的v聚合在一起
        // ("a",1), ("b", 2), ("a", 3)
        // (a, (1,3))
        val rdd2: RDD[(String, Int)] = rdd.reduceByKey(_+_)
        rdd2.collect().foreach(println)
//        (a,4)
//        (b,2)


        sc.stop()

    }
    class User {

    }
}
